package com.jdrx.sw.sewage.mq;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jdrx.sw.sewage.beans.mq.IOTCommandStatus;
import com.jdrx.sw.sewage.service.common.CommandService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "iot-forward-command-status-smart", consumerGroup = "iot-forward-command-status-sewage-group-smart", consumeThreadMax = 1)
public class CommandStatusListener implements RocketMQListener<String> {

    private static final Logger logger = LoggerFactory.getLogger(CommandStatusListener.class);
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private CommandService commandService;

    @Override
    public void onMessage(String message){
        logger.info("收到mq命令回执数据:" + message);
        try {
            IOTCommandStatus map = objectMapper.readValue(message, IOTCommandStatus.class);
            commandService.handleCommandData(map);
        } catch (Exception e) {
            logger.error("数据处理失败", e);
        }
    }
}
